package com.shushan.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.android.net.bean.NetRetBean;
import com.android.net.core.common.RequestType;
import com.android.net.helper.NetHelper;
import com.android.net.listener.common.CallbackCode;
import com.android.net.url.UrlParse;
import com.shushan.base.Constants;
import com.shushan.network.UrlCommParse;
import com.shushan.network.UrlConst;
import com.shushan.network.listener.NetStrCommListener;
import com.shushan.shushanbao.BabyApplication;
import com.shushan.ui.FloatToast;
import com.shushan.util.DateUtils;
import com.shushan.util.SharedPreferencesUtils;

/**
 * @ClassName: UnlockChildReceiver
 * @Desciption: 解除锁小孩密码广播接收器
 * @author: yichaohua
 * @date: 2018-06-21
 */
public class UnlockChildReceiver extends BroadcastReceiver {

    private static final String TAG = "UnlockChildReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(TAG,"onReceive:" + DateUtils.getNowDate());

        SharedPreferencesUtils.setBooleanDate(Constants.LOCK_CHILD_PSW_SHAREPREFERS_KEY,false);

        FloatToast.makeText(context,"远程锁屏已关闭").show();
        
        updateLockOver(context);
    }

    private void updateLockOver(Context context) {
        UrlParse urlParse = new UrlCommParse(context, UrlConst.BASE_URL).appendRegion(UrlConst.UPDATE_LOCK_OVER);
        urlParse.putValue("child_id", BabyApplication.getInstance().getCurrentChildId());

        NetHelper.create()
                .url(urlParse.toStringOnlyHeader())
                .param(urlParse.toStringOnlyParam())
                .request(RequestType.REQUEST_TYPE_POST, new NetStrCommListener() {

                    @Override
                    protected void onSuccess(String data) {

                    }

                    @Override
                    protected void onError(CallbackCode errorCode, NetRetBean netRetBean) {
                    }
                });
    }
}
